<template>
  <el-card>
    <!-- 搜索区域 S -->
    <el-row type="flex" justify="space-between" align="middle">
      <div>
        <!-- 输入框 -->
        <el-input size="small" v-model="q.query" placeholder="请输入内容">
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="search"
          ></el-button>
        </el-input>
      </div>
      <!-- 增加按钮 -->
      <el-button type="primary" icon="el-icon-plus" size="small"
        >增加商品</el-button
      >
    </el-row>
    <!-- 搜索区域 E -->

    <!-- 表格区域 S-->
    <!--el-table 上面的 data表示表格的数据 -->
    <!--el-table-column  label 表示表头的文字， prop展示数据的字段名称  type表示列的类型（index，selection）-->
    <br />
    <el-table border :data="tableData">
      <el-table-column type="selection"></el-table-column>
      <el-table-column
        type="index"
        prop="goods_id"
        label="ID"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="goods_name"
        label="商品名称"
        width="450"
      ></el-table-column>
      <el-table-column prop="goods_price" label="价格"></el-table-column>
      <el-table-column prop="goods_number" label="数量"></el-table-column>
      <el-table-column prop="goods_state" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.goods_state">通过</el-tag>
          <el-tag v-else>未通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="hot_mumber" label="是否热销">
        <template slot-scope="scope">
          <el-switch :value="scope.row.is_promote"> </el-switch>
        </template>
      </el-table-column>
      <el-table-column prop="add_time" label="创建时间" width="190">
        <template slot-scope="scope">
          {{ scope.row.add_time | formateTime }}
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="160">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格区域 E-->

    <!-- 分页区域 S-->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="q.pagenum"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="q.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNum"
    >
    </el-pagination>
    <!-- 分页区域 E-->
  </el-card>
</template>

<script>
import list from "@/mixins/index";
import { getGoodsList } from "@/api/goods";
export default {
  name: "GoodsList",
  mixins:[list],
  data() {
    return {
      q: {
        query: null,
      },
    };
  },
  filters: {
    formateTime(val) {
      let time = new Date(val * 1000);
      return time.toLocaleString();
    },
  },
  methods: {
    handleClick(row) {
      console.log(row);
    },
    async getGoods() {
      try {
        const { data } = await getGoodsList(this.q);
        // console.log(data);
        this.tableData = data.goods;
        this.totalNum = data.total;
      } catch (error) {
        console.log(error);
      }
    },
    search() {
      // this.pagenum = 1;
      this.getGoods();
    },
  },
};
</script>

<style>
</style>